package cz.muni.fi.pa165.business.service.utils;

import cz.muni.fi.pa165.api.dto.ForestDTO;
import cz.muni.fi.pa165.business.entity.Forest;
import java.util.ArrayList;
import java.util.List;

/**
 * Collection of transformation methods between Forest and ForestDTO objects
 *
 * @author Matej Cimbora
 */
public class ForestObjectTransformer {

    private ForestObjectTransformer() {
    }

    public static Forest forestDTOToForest(ForestDTO forestDTO) {
        Forest forest = new Forest();
        forest.setId(forestDTO.getId());
        forest.setName(forestDTO.getName());
        forest.setLocationInfo(forestDTO.getLocationInfo());
        return forest;
    }

    public static ForestDTO forestToForestDTO(Forest forest) {
        if (forest == null) {
            return null;
        }
        ForestDTO forestDTO = new ForestDTO();
        forestDTO.setId(forest.getId());
        forestDTO.setName(forest.getName());
        forestDTO.setLocationInfo(forest.getLocationInfo());
        return forestDTO;
    }

    public static List<ForestDTO> forestListToForestDTOList(List<Forest> forestList) {
        List<ForestDTO> result = new ArrayList<>();
        for (Forest forest : forestList) {
            result.add(forestToForestDTO(forest));
        }
        return result;
    }
}
